package com.fish.design.create.singleton.lazy;

/**
 *
 * @PACKAGE_NAME: com.fish.design.create.singleton.lazy
 * @Author: wangyingbin
 * @Date: 2021/11/3 20:48
 * @Description: 静态内部类
 */

public class LazyInnerClassSingleton {

    private LazyInnerClassSingleton(){
        if(LazyHolder.INSTANCE !=null){
            throw new RuntimeException("不允许创建多个实例");
        }
    }

    private static class LazyHolder{
        private static final LazyInnerClassSingleton INSTANCE = new LazyInnerClassSingleton();
    }
    // 每一个关键字都不是多余的，static是为了使单例的空间共享，保证这个方法不会被重写、重载
    private static final LazyInnerClassSingleton getInstance(){
        // 在返回结果前，一定会先加载内部类
        return LazyHolder.INSTANCE;
    }
}
